import * as sdk from './fetch';

/**
 *  查询我的许愿池（不分页个人中心）
 * @param params
 * @returns
 */
async function getUserWishItemsList(params = {}): Promise<any> {
  let result = await sdk.post<any>(`wish/list`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}

/**
 * 查询我的许愿池信息（分页）
 * @param params 
 */
async function getUserWishItemsPage(params={}):Promise<any> {
  let result = await sdk.post<any>(`wish/page`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}

/**
 *  查询许愿列表接口
 * @param params
 * @returns
 */
async function getWishProductItems(params = {}): Promise<any> {
  let result = await sdk.post<any>(`doll/getWishList`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}

/**
 * 许愿
 * @param params 
 * @returns 
 */
async function createWishItem(params = {}): Promise<any> {

  let result = {
    context: "",
    code: "",
    message: ""
  }
  try {
    result = await sdk.post<any>(`wish/add`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }


  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}

/**
 * 取消许愿
 * @param params 
 * @returns 
 */
async function cancelWishItem(params = {}): Promise<any> {

  let result = {
    context: "",
    code: "",
    message: ""
  }
  try {
    result = await sdk.get<any>(`wish/cancel/${params.id}`, {
      ...params,
    });
  }
  catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}

/**
 * 批量删除许愿
 * @param params 
 * @returns 
 */
async function removeWishItems(params = {}): Promise<any> {

  let result = {
    context: "",
    code: "",
    message: ""
  }
  try {
    result = await sdk.get<any>(`wish/delete`, {
      ...params,
    });
  }
  catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message
  };
}


export default {
  getUserWishItemsList,
  getWishProductItems,
  createWishItem,
  cancelWishItem,
  getUserWishItemsPage,
  removeWishItems
}